#!python3
#fastpai架构搭建的网页结构， 分左右， 前端用了twitter出的bootstrap3开源架构
#最终实现一个一左一右的网页， 菜单在左边， 显示的页面在右面，这样一个web框架。
from fastapi import FastAPI
from starlette.requests import Request
import os
from fastapi.templating import Jinja2Templates
from starlette.staticfiles import StaticFiles
from starlette.responses import RedirectResponse
from typing import List
from fastapi import FastAPI, File, UploadFile
from starlette.responses import HTMLResponse
import uvicorn


#主页， 分左右
index='''
   <frameset cols="8%,*"/>
      <frame src="left" name="left" id="left" frameborder="0" scrolling="no"/>
      <frame src="right" name="right1" id="right1"/>
   </frameset>
'''

#网页head， 做继承用，主要是调用了bootstrap3这个UI界面
head='''
<head>
	<meta charset="utf-8"> 
	<title>demo</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
'''
#左边的网页
left_page='''
{}
<body>
<ul class="nav nav-tabs">
  <li role="presentation" ><a href="/right" target=right1>Home</a></li>
  <li role="presentation"><a href="http://www.baidu.com" target="right1">Profile11</a></li>

  <li role="presentation" class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Message <span class="caret"></span></a>
      <ul class="dropdown-menu">
          <li><a href="#">Action</a></li>
          <li><a href="#">Another action</a></li>
          <li><a href="#">Something else here</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">Separated link</a></li>
    </ul>
  <li role="presentation" class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
    <ul class="dropdown-menu">
          <li><a href="#">Action</a></li>
          <li><a href="#">Another action</a></li>
          <li><a href="#">Something else here</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">Separated link</a></li>
    </ul>
</ul>
</body>
</html>
'''

#默认右面的主页面， 这里简单做了一个表格和一些按钮
default='''
{}
<body>
<table class="table">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
    <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>
<!-- Standard button -->
<button type="button" class="btn btn-default">（默认样式）Default</button>

<!-- Provides extra visual weight and identifies the primary action in a set of buttons -->
<button type="button" class="btn btn-primary">（首选项）Primary</button>

<!-- Indicates a successful or positive action -->
<button type="button" class="btn btn-success">（成功）Success</button>

<!-- Contextual button for informational alert messages -->
<button type="button" class="btn btn-info">（一般信息）Info</button>

<!-- Indicates caution should be taken with this action -->
<button type="button" class="btn btn-warning">（警告）Warning</button>

<!-- Indicates a dangerous or potentially negative action -->
<button type="button" class="btn btn-danger">（危险）Danger</button>

<!-- Deemphasize a button by making it look like a link while maintaining button behavior -->
<button type="button" class="btn btn-link">（链接）Link</button>
</body>
'''
app = FastAPI()
location='logs'
location_FW='FW'
app.mount('/static', StaticFiles(directory=location), name='static') 


@app.get("/about")
def about():
    return "hello"



#左边的菜单=left_page加上head
@app.get("/left")
def left():
    #return RedirectResponse(url='/lists')
    return HTMLResponse(content=left_page.format(head))


#默认主目录
@app.get("/")
def main():

    return HTMLResponse(content=index)





#默认右边显示
@app.get("/right")
def right():

    return HTMLResponse(content=default.format(head))


if __name__ == "__main__":

    print('当前程序名称为:',os.path.basename(__file__))
    filename=os.path.basename(__file__).split('.')[0]
    
    
    
    

    uvicorn.run(filename+":app", host="0.0.0.0",port=8002,log_level="info")
